package com.st.controller;



import com.st.base.BaseResult;
import com.st.po.GoodsSelectLikePo;
import com.st.pojo.Goods;
import com.st.service.GoodsService;
import com.st.vo.GetGoodsVo;
import com.st.vo.GoodsConditionsVo;
import com.st.vo.GoodsSelectLikeVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(path = "goods")
@Tag(name="商品表",description = "表示商品所有需要用到的方法")
public class GoodsController {

    @Resource
    private GoodsService goodsService;

    @Operation(summary = "goodLike",description = "这里表示对商品分类模糊查询并倒序返回")
    @RequestMapping(path = "goodsLike",method = RequestMethod.POST)
    public BaseResult goodsLike(@Valid @RequestBody GoodsSelectLikePo goodsSelectLikePo){
        List<GoodsSelectLikeVo> goodsSelectLikeVos = goodsService.getList(goodsSelectLikePo);
            return BaseResult.ok(goodsSelectLikeVos);
    }


    @Operation(summary = "getConditionsList",description = "商品详情id必传，其它的非必传根据选项传入所返回的数据也不同")
    @Parameters({
            @Parameter(name = "detailId",description = "商品分类id必传"),
            @Parameter(name = "sale",description = "销量标记未传表示升序排序int类型传入表示降序排序"),
            @Parameter(name = "createTime",description = "时间标记未传表示升序排序int类型传入表示降序排序"),
            @Parameter(name = "price",description = "价格标记未传表示升序排序int类型传入表示降序排序"),
            @Parameter(name = "Standard",description = "给对应的类目名给出相应的列表"),
    })
    @RequestMapping(path = "getConditionsList",method = RequestMethod.GET)
    public BaseResult<GoodsConditionsVo> getConditionsList(@RequestParam("detailId") Integer detailId,
                                        @RequestParam(value = "sale",required = false) Integer sale,
                                        @RequestParam(value = "price",required = false) Integer price,
                                        @RequestParam(value = "createTime",required = false) Integer createTime,
                                        @RequestParam(value = "Standard",required = false) String Standard){
    List<GoodsConditionsVo> getGoodsList = goodsService.getConditionsList(detailId,sale,price,createTime,Standard);
            if (getGoodsList!=null&&getGoodsList.size()>0){
                return BaseResult.ok(getGoodsList);
            }
                return BaseResult.error("没找到所选的类型");
    }

    @Operation(summary = "getGoods",description = "根据id查找商品详情")
    @RequestMapping(path = "getGoods",method = RequestMethod.GET)
    public BaseResult<GetGoodsVo> getGoods(@RequestParam(value = "id")Integer id){
      GetGoodsVo goods = goodsService.getGoods(id);
      if (goods!=null){
          return BaseResult.ok(goods);
      }
      return BaseResult.error("没找到该花");
    }

}
